package com.geostar.constructionland.index.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.geostar.constructionland.index.entity.LandUseIndexEntity;
import com.geostar.constructionland.index.entity.model.LandUseIndexAddModel;
import com.geostar.constructionland.index.entity.model.LandUseIndexDelModel;
import com.geostar.constructionland.index.entity.server.ServerResponse;
import com.geostar.constructionland.index.service.LandUseIndexService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/***
 * 指标信息
 * @author wuyongzhi
 */
@RestController
@RequestMapping("/IndexInfo")
@Api(tags = "指标信息相关接口")
public class IndexInfoController {
    @Resource
    LandUseIndexService landUseIndexService;

    @ApiOperation(value = "新增用地指标")
    @PostMapping(value = "/insertLandUseIndex")
    @ResponseBody
    public ServerResponse insertLandUseIndex(@RequestBody LandUseIndexAddModel landUseIndexAddModel) {
        ServerResponse serverResponse = ServerResponse.createBySuccess();
        List<LandUseIndexEntity> landUseIndexes = landUseIndexAddModel.getLandUseIndexes();
        String businessId = landUseIndexAddModel.getBusinessId();
        if(landUseIndexes == null || landUseIndexes.size() == 0 || StringUtils.isBlank(businessId)) {
            serverResponse = ServerResponse.createByErrorMessage("传入参数有误：用地指标数组和业务ID不能为空！");
        } else {
            landUseIndexService.insertLandUseIndex(landUseIndexAddModel);
        }
        return serverResponse;
    }

    @ApiOperation(value = "删除用地指标")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "landUseIndexId", value = "用地指标表主键ID", required = true),
            @ApiImplicitParam(name = "businessId", value = "业务ID", required = true),
            @ApiImplicitParam(name = "attachmentDirId", value = "附件目录ID"),
            @ApiImplicitParam(name = "userid", value = "用户ID"),
            @ApiImplicitParam(name = "username", value = "用户名称")
    })
    @PostMapping(value = "/deleteLandUseIndex")
    @ResponseBody
    public ServerResponse deleteLandUseIndex(@Valid LandUseIndexDelModel landUseIndexDelModel) {
        ServerResponse serverResponse = ServerResponse.createBySuccess();
        String landUseIndexId = landUseIndexDelModel.getLandUseIndexId();
        String businessId = landUseIndexDelModel.getBusinessId();
        if(StringUtils.isNotBlank(landUseIndexId) && StringUtils.isNotBlank(businessId)) {
            landUseIndexService.deleteLandUseIndex(landUseIndexDelModel);
        } else {
            serverResponse = ServerResponse.createByErrorMessage("传入参数有误：用地指标表主键ID和业务ID不能为空！");
        }
        return serverResponse;
    }

    @ApiOperation(value = "更新指标出库台账信息")
    @PostMapping(value = "/updateInxOutStorageAcot")
    @ResponseBody
    public ServerResponse updateInxOutStorageAcot(@RequestBody LandUseIndexAddModel landUseIndexAddModel) {
        ServerResponse serverResponse = ServerResponse.createBySuccess();
        List<LandUseIndexEntity> landUseIndexes = landUseIndexAddModel.getLandUseIndexes();
        String businessId = landUseIndexAddModel.getBusinessId();
        if(landUseIndexes == null || landUseIndexes.size() == 0 || StringUtils.isBlank(businessId)) {
            serverResponse = ServerResponse.createByErrorMessage("传入参数有误：用地指标数组和业务ID不能为空！");
        } else {
            landUseIndexService.updateInxOutStorageAcot(landUseIndexAddModel);
        }
        return serverResponse;
    }
}
